<template>
  <el-dialog title="编辑分类" :width="width" :visible.sync="isShowVisible" center :before-close="handle_close">
    <el-card v-loading="isLoading">
      <el-form label-width="105px" :model="updateData" ref="fromData">
        <el-row>
          <el-col :span="12">
            <el-form-item label="分类名称:" prop="fname">
              <el-input v-model="updateData.fname"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="分类编码:" prop="fnumber">
              <el-input v-model="updateData.fnumber"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="saveGroup">保存</el-button>
      <el-button @click="handle_close">取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import Group from "@/api/psyManage/Group";

export default {
  name: 'update_tree',
  props: {
    updateOne: Object,
    width: { type: String, default: '40vw' },

  },
  data() {
    return {
      isShowVisible: true,
      groupData: {},
      groupList: [],
      isLoading: '',
      updateData:{},
      formData:{},
      nodeId:'',
      fid:null,
    }
  },
  created() {
    this.init()
  },
  methods: {
    async init() {
      console.log(this.updateOne.nodeId)
      const api = new Group();
      const resp = await api.selectOne({pid:this.updateOne.nodeId}).catch(()=>this.isLoading=false)
      this.updateData=resp.data
    },

    //提交
    saveGroup() {
      console.log("保存")
      this.$refs['fromData'].validate((valid) => {
        if (valid) {
          const loading = this._loading();
          const api = new Group();
         /* if (this.updateData.fstatus==="BASE"){
            this.$tie.showError('存在已启用数据无法修改！')
            loading.close();
            return;
          }
          this.updateData.fstatus=1;*/
          if(this.updateData.fstatus==="BASE"){
            this.updateData.fstatus=0;
          }else if(this.updateData.fstatus==="AUX") {
            this.updateData.fstatus = 1;
          }else{}
          console.log(this.updateData)
          api.update(this.updateData).then(res => {
            loading.close();
            this.$tie.showSuccess(res.message)
            this.$emit("close", {name:"treeUpdate", isRefreshTree: true});
          }).catch(e => loading.close())
        }
      })

    },

    handle_close() {
      this.$emit("close",{name:"treeUpdate",isRefreshTree:false});
    },
    //加载提示
    _loading() {
      return this.$loading({
        lock: true,
        text: '请耐心等待.....',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
    }
  },

}
</script>

<style scoped>
</style>
